<template>
	<view class="body">
		<view v-if="loading">
			<loading></loading>
		</view>
		<view class="container" v-else>
			<view class="topTitle" @click="toAdd">
				<text>添加学生</text>
			</view>
			<view class="reportView ">
				<view class="container-1"  :data-index="index" v-for="(i, index) in list">
					<view class="left">
						<view class="bottom">
							<text class="name">{{i.studentName}}</text>
							<text class="sex">{{i.sex==0?'男':'女'}}</text>
							<text >身份证{{i.idCard}}</text>			
						</view>
					</view>
					<view class="right" @click="open(i)">
						<text class="dot"></text>
						<text class="dot"></text>
						<text class="dot"></text>
					</view>
				</view>
			</view>
			<view class="load-more">
				<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
				<text  v-if="botShow">已经到底了</text>
			</view>
		</view>
		
		<uni-popup ref="popup" type="bottom">
			<view class="popup">
				<text @click="info">详细信息</text>
				<text @click="update">修改</text>
				<text  class="del">删除</text>
				<text class="cancel" @click="close">取消</text>
			</view>
		</uni-popup>
	</view>
	
</template>
<script>
	import { getStudentList } from '@/api/school/school'
	import loading from '@/components/loading/loading'
	export default{
		data(){
			return{
				list:[],
				pageForm:{
					pageNo:1,
					pageSize:10,
				},
				active:null,
				loadShow:false,
				botShow:false,
				loading:true,
			}
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getList()
			}
			
		},
		created() {
			 this.getList()
		},
		methods:{
			open(e){
				this.active=e
				console.log(e)
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			},
			getList(){
				getStudentList(this.pageForm).then(res=>{
					if(res.data.list.length > 0){
						this.list.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
				})
			},
			toAdd(){
				this.$tab.navigateTo(`/pages/school/student/add`)
			},
			
			//删除方法
			delData() {
				console.log("删除")
				uni.showModal({
					title: '提示',
					content: "确认删除该职位？",
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			update(){
				this.close()
				this.$tab.navigateTo(`/pages/school/student/add?id=` + this.active.id)
				
			},
			info(){
				this.close()
				this.$tab.navigateTo(`/pages/school/student/info?id=` + this.active.id)
			}
		}
	}
</script>

<style lang="scss">
	
	.container{
		background-color: #fff;
		min-height:100vh;
		padding-top: 20px;
		.reportView{
			width: calc(100% - 40rpx);
			margin: 0 auto;
			font-size: 14px;
			font-family: Inter-Thin, Inter;
			
		}
		
		.container-1 {
			margin-top: 26rpx;
			margin-bottom: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding:0 5px;
			border-bottom:  1px solid #E1E1E1;
			
			.left{
				width: 92%;
				text{
					line-height: 30px;
					font-size: 12px;
					font-family: Inter-Regular, Inter;
					font-weight: 400;
					color: #5E5E5E;
				}
				.bottom{
					display: flex;
					justify-content: flex-start;
					margin-top: 10px;
					padding-bottom: 10px;
					text{
						display: block;
						text-align: center;
					}
					.name{
						width: 60px;
					}
					.sex{
						width: 40px;
						margin-right: 20px;
					}

				}
				.blue{
					color: #508CFF;
				}
				.red{
					color: #F26D6D;
				}
				.green{
					color: #50B987;
				}
				.orange{
					color: #FF9A50;
				}
				
			}
			.right{
				display: flex;
				.dot{
					width: 3px;
					height: 3px;
					background: #A3A3A3;
					opacity: 1;
					margin-right: 3px;
					border-radius: 3px;
				}
			}
		}
	}
	.topTitle{
		font-size: 14px;
		font-family: Inter-Regular, Inter;
		font-weight: 400;
		color: #508CFF;
		padding-left: 25px;
	}
	.load-more{
		display: block;
		padding: 20px;
		margin: 0 auto;
		text-align: center;
	}
	.popup{
		height: 205px;
		background: #FFFFFF;
		text{
			line-height: 50px;
			display: block;
			text-align: center;
			font-family: Roboto-Regular, Roboto;
			font-weight: 400;
			color: #000000;
			font-size: 16px;
		}
		.cancel{
			color: #F26D6D;
		}
	}
</style>